﻿package com.gengine.resource.info
{
    import com.gengine.core.*;
    import flash.display.*;
    import flash.utils.*;

    public class ResourceInfo extends ClassProxy
    {
        public var loaderInfo:LoaderInfo;
        public var name:String;
        public var time:String;
        public var path:String;
        public var type:String;
        public var callBackId:uint;
        private var _data:Object;
        public var extData:Object;
        public var isHasLoaded:Boolean = false;
        public var isLoaded:Boolean;
        public var isLoading:Boolean = false;
        public var isAddToPreLoad:Boolean = false;
        public var isPreLoading:Boolean = false;
        private var _loadCacheBytes:ByteArray = null;
        private var _referenceCount:int = 0;
        private var _isDispose:Boolean = false;
        private var _bytesDisposeTime:Number = 0;
        public var loaclPath:String;
        private var _soPath:String = null;
        public static var resCount:Number = 0;
        public static const ReleaseByteTime:Number = 180000;

        public function ResourceInfo(param1:Object = null)
        {
            if (param1)
            {
                this.initFromObject(param1);
            }
            return;
        }// end function

        public function initFromObject(param1:Object) : void
        {
            this.type = param1.type;
            this.name = param1.name;
            this.time = param1.time;
            this.callBackId = param1.callBackId;
            this.path = param1.path + "?v=" + param1.time;
            return;
        }// end function

        public function resetDisposeTime() : void
        {
            this._bytesDisposeTime = getTimer() + ReleaseByteTime;
            return;
        }// end function

        public function get soPath() : String
        {
            var _loc_1:int = 0;
            if (this._soPath == null)
            {
                if (this.loaclPath)
                {
                    _loc_1 = this.loaclPath.lastIndexOf("?");
                    if (_loc_1 > -1)
                    {
                        this._soPath = this.loaclPath.slice(0, _loc_1);
                    }
                    else
                    {
                        this._soPath = this.loaclPath;
                    }
                }
                else
                {
                    this._soPath = "";
                }
            }
            return this._soPath;
        }// end function

        public function get isDispose() : Boolean
        {
            return this._isDispose;
        }// end function

        public function set data(param1:Object) : void
        {
            this._data = param1;
            this._isDispose = false;
            return;
        }// end function

        public function addReference() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount + 1;
            _loc_1._referenceCount = _loc_2;
            return;
        }// end function

        public function removeReference() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._referenceCount - 1;
            _loc_1._referenceCount = _loc_2;
            return;
        }// end function

        public function get referenceCount() : int
        {
            return this._referenceCount;
        }// end function

        public function dispose() : void
        {
            this._isDispose = true;
            this._data = null;
            this._referenceCount = 0;
            this.isLoaded = false;
            this.isLoading = false;
            this.extData = null;
            if (this.loaderInfo && this.loaderInfo.loader)
            {
                this.unload(this.loaderInfo);
                this.loaderInfo = null;
            }
            return;
        }// end function

        protected function unload(param1:LoaderInfo) : void
        {
            try
            {
                param1.loader.close();
            }
            catch (e:Error)
            {
            }
            param1.loader.unload();
            return;
        }// end function

        public function isLoadedByteArray() : Boolean
        {
            if (this._loadCacheBytes)
            {
                return true;
            }
            return false;
        }// end function

        public function get cacheBytes() : ByteArray
        {
            if (this._loadCacheBytes)
            {
                return this._loadCacheBytes;
            }
            if (this.loaderInfo)
            {
                this.writeCacheBytes(this.loaderInfo.bytes);
            }
            return this._loadCacheBytes;
        }// end function

        public function set cacheBytes(param1:ByteArray) : void
        {
            this.writeCacheBytes(param1);
            if (param1)
            {
                resCount = resCount + param1.length;
            }
            return;
        }// end function

        public function clearCacheBytes() : void
        {
            if (this._loadCacheBytes)
            {
                this._loadCacheBytes = null;
            }
            return;
        }// end function

        protected function writeCacheBytes(param1:ByteArray) : void
        {
            return;
        }// end function

        public function get bytesDisposeTime() : Number
        {
            return this._bytesDisposeTime;
        }// end function

    }
}
